const surroundLine = {
  // 顶点着色器
  vertexShader: `
    #define PI 3.14159265359

    uniform  float uStartTime;
    uniform  float time;
    uniform  float uRange;
    uniform  float uSpeed;

    uniform vec3 uColor;
    uniform vec3 uActive;
    uniform vec3 uMin;
    uniform vec3 uMax;

    varying vec3 vColor;

    float lerp(float x, float y, float t) {
        return (1.0 - t) * x + t * y;
    }
    void main() { 
        // 当动画结束前，改变颜色
        if (uStartTime >= 0.99) {
            float iTime = mod(time * uSpeed, 1.0);
            // 获得整个区间的某个位置的坐标分量
            float rangeZ = lerp(uMin.z, uMax.z, iTime);
            if ( position.z > rangeZ && position.z< rangeZ+uRange) {

                float index = 1.0 - sin((position.z - rangeZ) / uRange * PI);
                // float index = 1.0 - (position.z - rangeZ) / uRange;
                float r = lerp(uActive.r, uColor.r, index);
                float g = lerp(uActive.g, uColor.g, index);
                float b = lerp(uActive.b, uColor.b, index);

                vColor = vec3(r, g, b);
            } else {
                vColor = uColor;
            }
        }
        vec3 vPosition = vec3(position.x, position.y* uStartTime, position.z );
        gl_Position = projectionMatrix * modelViewMatrix * vec4(vPosition, 1.0);
    } 
    `,
  // 片元着色器
  fragmentShader: ` 
    uniform float uOpacity;
    uniform float uStartTime;

    varying vec3 vColor; 

    void main() {

        gl_FragColor = vec4(vColor, uOpacity * uStartTime);
    }
    `,
};
export default {
  surroundLine,
};
